/**
 * 版权所有：厦门市巨龙信息科技有限公司
 * Copyright 2023 Xiamen Dragoninfo Eng. Co. Ltd.
 * All right reserved.
 */
package com.github.alfred.database.adapter.impl;

import com.baomidou.mybatisplus.annotation.DbType;
import com.github.alfred.database.DatabaseAdapterHandler;
import com.github.alfred.database.adapter.IDatabaseAdapterProvider;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

/**
 * 类说明
 *
 * @author chengh
 * @date 2023/9/15 13:35
 */
@Service
public class OracleAdapterProvider implements IDatabaseAdapterProvider, InitializingBean {
    public static final String SORT_FORMAT = "%s  %s  %s";

    @Override
    public String getSortNullsLast(String column, Sort.Direction direction) {
        return String.format(SORT_FORMAT, column, direction, "nulls last");
    }

    @Override
    public String getSortNullsFirst(String column, Sort.Direction direction) {
        return String.format(SORT_FORMAT, column, direction, "nulls first");
    }

    @Override
    public String strToTimestamp(String time) {
        return String.format(" to_timestamp('%s', 'YYYY-MM-DD HH24:MI:SS:FF6') ", time);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        DatabaseAdapterHandler.registerService(DbType.ORACLE.getDb(), this);
    }

}
